#ifndef LINEEXTRACTION_H
#define LINEEXTRACTION_H

#define NUMR 800
#define RSTEP 5
#define RSIZE 161
#define THETASTEP 2
#define THETASIZE 90
#define THETAMIN -88
#define THETAMAX 90
//#define THETASTEP 4
//#define THETASIZE 45
//#define THETAMIN -86
//#define THETAMAX 90
#define MAXLINES 500
#define MAXSEGMENTS 750
#define TRIGFACTOR 1000
//#define PEAKTHRESHOLD 75
#define PEAKTHRESHOLD 20
#define ERRORCHECK 1
#define GAP 2

#include "LFOSCommon.h"

typedef struct{
	int theta;
	int r;
} Line;

typedef struct{
	int theta;
	int r;
	int accumVal;
} Peak;

bool PeakCompare(Peak p1, Peak p2);

class LineExtraction
{
public:

	LineSegment* ExtractLines(bool* frame, unsigned int& numLineSegments, Point* edgePoints, int numPoints);

private:

	//Finds the local maxima in the accumulator array
	//returns the number of peaks found and sets the theta and
	//r values for each peak in the arrays
	int FindPeaks(int thetas[], int rs[]);

	//Creates Line Segments from the given lines
	//returns the number of segments
	int FindSegments(Line lines[], unsigned int numLines, bool* frame);

	int TraceLine(bool* frame, int r, int theta, Point start, int error, int numSegments);

	int cotLookup(int m);

	LineSegment FoundLineSegments[MAXSEGMENTS];
	short Accumulator[THETASIZE/2][RSIZE];
	Point firstPoint[THETASIZE/2][RSIZE];
	bool visited[PIXELS];
	//Point* linePoints[THETASIZE][RSIZE];
	//Point edges[PIXELS];
	static short cos[THETASIZE];
	static short sin[THETASIZE];
};

#endif
